package com.zhiwei.codesecurity.common.enums;
import com.zhiwei.codesecurity.common.base.IBaseEnum;

public enum ResultCode implements IBaseEnum<ResultCode> {
    SUCCESS(0, "成功"),

    /**
     * 全局业务异常大类
     */
    EXCEPTION_BUSINESS(100100, "业务异常"),

    EXCEPTION_BUSINESS_PARAM_MISS(100101, "参数缺失"),

    EXCEPTION_BUSINESS_PARAM_ERROR(100102, "参数错误"),

    /**
     * 代码出现异常
     */
    EXCEPTION_UNKWOWN(100200, "服务繁忙，请稍后再试"),

    EXCEPTION_BS(100300, "系统基础服务异常"),

    /**
     * 调用远程接口出现异常
     */
    EXCEPTION_RPC(100400, "远程服务调用异常"),

    /**
     * 调用远程接口正常返回数据，但是返回数据出现错误
     */
    EXCEPTION_RPC_RSP_ERROR(100401, "远程服务调用返回的业务数据错误"),

    EXCEPTION_CACHE(100500, "缓存服务异常"),

    /**
     * @deprecated
     * 这是个业务异常的一个小类,用EXCEPTION_BUSINESS_PARAM_MISS或者EXCEPTION_BUSINESS_PARAM_ERROR代替
     */
    EXCEPTION_PARAMS(100600, "参数错误"),

    EXCEPTION_INVALIDE_REQ(100700, "无效的请求"),

    EXCEPTION_SECURITY(100900, "安全错误"),

    ;


    private Integer key;
    private String value;

    private ResultCode(Integer key, String value) {
        this.key = key;
        this.value = value;
    }

    @Override
    public Integer getKey() {
        return this.key;
    }

    @Override
    public String getValue() {
        return this.value;
    }

    @Override
    public ResultCode setValue(String value) {
        this.value = value;
        return this;
    }

    @Override
    public boolean isSuccess(Integer key) {
        if (null == key) return false;
        return this.key.intValue() == key.intValue();
    }
}
